{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content"> 
				<div class="row row-lg"> 
					<div class="col-sm-12"> 
						<div class="row" id="searchGroup">
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">订单号</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="order_sn" placeholder="订单号" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">订单状态</button>
									</div>
									<select class="form-control" id="status">
										<option value="">请选择</option>
										<option value="1">已支付</option>
										<option value="0">待支付</option>
										<!--<option value="2">已取消</option>-->
									</select>
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">会员名称</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="vip_name" placeholder="会员名称" />
								</div>
							</div>
                            <div class="col-sm-2">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">红娘名称</button>
                                    </div>
                                    <input type="text" autocomplete="off" class="form-control" id="m_name" placeholder="红娘名称" />
                                </div>
                            </div>
							<!-- search end -->
							<div class="col-sm-1">
								<button type="button" class="btn btn-success " onclick="CodeGoods.search()" id="">
									<i class="fa fa-search"></i>&nbsp;搜索
								</button>
							</div>
						</div>
						<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">
						</div>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};

	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
 			{title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '订单号', field: 'order_sn', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '订单状态', field: 'status', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.statusFormatter},
 			{title: '会员名称', field: 'vip_name', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '会员价格', field: 'vip_price', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '红娘名称', field: 'name', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.nameFormatter},
            {title: '用户昵称', field: 'nickname', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '创建时间', field: 'createtime', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.createtimeFormatter},
 			{title: '操作', field: '', visible: true, align: 'center', valign: 'middle',formatter: 'CodeGoods.buttonFormatter'},
 		];
 	};

	CodeGoods.buttonFormatter = function(value,row,index) {
		if(row.id){
			var str= '';
			{if condition="in_array('backend/ZhVipOrder/view',session('backend.nodes')) || session('backend.role_id') eq 1"}
			str += '<button type="button" class="btn btn-info btn-xs" title="查看详情"  onclick="CodeGoods.view('+row.id+')"><i class="fa fa-eye"></i>&nbsp;查看详情</button>&nbsp;';
			{/if}
			return str;
		}
	}
    CodeGoods.nameFormatter = function(value,row,index) {
        if(row.is_personal == '1'){
            return row.name;
        }else if(row.is_personal == '0'){
            return row.organization_name;
        }else{
            return '无';

        }
    }

	CodeGoods.statusFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">已支付</span>';
				break;
				case '0':
					return '<span class="label label-danger">待支付</span>';
				break;
				case '2':
					return '<span class="label label-info">已取消</span>';
				break;
			}
		}
	}

	CodeGoods.createtimeFormatter = function(value,row,index) {
		if(value){
			return formatDateTime(value,'Y-m-d H:i:s');	
		}
	}

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['offset'] = 0;
		queryData['order_sn'] = $("#order_sn").val();
		queryData['status'] = $("#status").val();
		queryData['vip_name'] = $("#vip_name").val();
        queryData['m_name'] = $("#m_name").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.view = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhVipOrder/view?id='+value});
			if(!IsPC()){layer.full(index)}
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhVipOrder/view?id='+idx});
				this.layerIndex = index;
				if(!IsPC()){layer.full(index)}
			}
		}
	}


	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/ZhVipOrder/index"+url,defaultColunms,20);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});
</script>
{/block}